/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Symmetric2x2GameComponent.java
 *
 * Created on 17/Dez/2011, 13:25:20
 */

package intopo.game.impl.sym2x2;

import intopo.game.gui.AbstractGameEditorComponent;
import java.awt.BorderLayout;

/**
 *
 * @author <a href="mailto:mariano.pedro@gmail.com">Pedro Mariano</a>
 *
 * @version 1.0 17/Dez/2011
 */
public class Symmetric2x2GameComponent
	extends AbstractGameEditorComponent<Symmetric2x2Game, Symmetric2x2Strategy>
{

	/** Creates new form BeanForm */
	public Symmetric2x2GameComponent ()
	{
		initComponents();
		this.add (this.infoPanel, BorderLayout.SOUTH);
		this.updateInfoPanel (true);
	}

	@Override
	public String getConfigFileDescription () {
		throw new UnsupportedOperationException ("Not supported yet.");
	}

	@Override
	public Symmetric2x2Game getGame ()
	{
		float p00 = (Float) this.payoff00FormattedTextField.getValue ();
		float p01 = (Float) this.payoff01FormattedTextField.getValue ();
		float p10 = (Float) this.payoff10FormattedTextField.getValue ();
		float p11 = (Float) this.payoff11FormattedTextField.getValue ();
		return new Symmetric2x2Game (p00, p01, p10, p11);
	}

	@Override
	public void setGame (Symmetric2x2Game game)
	{
		this.payoff00FormattedTextField.setValue (new Float (game.getPayoff (0, 0)));
		this.payoff01FormattedTextField.setValue (new Float (game.getPayoff (0, 1)));
		this.payoff10FormattedTextField.setValue (new Float (game.getPayoff (1, 0)));
		this.payoff11FormattedTextField.setValue (new Float (game.getPayoff (1, 1)));
	}


	/** This method is called from within the constructor to
	 * initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is
	 * always regenerated by the Form Editor.
	 */
    @SuppressWarnings("unchecked")
   // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
   private void initComponents() {

      payoffMatrixPanel = new javax.swing.JPanel();
      payoff00FormattedTextField = new javax.swing.JFormattedTextField();
      payoff01FormattedTextField = new javax.swing.JFormattedTextField();
      payoff10FormattedTextField = new javax.swing.JFormattedTextField();
      payoff11FormattedTextField = new javax.swing.JFormattedTextField();

      setBorder(javax.swing.BorderFactory.createTitledBorder("game parameters"));

      payoffMatrixPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("payoff matrix"));
      payoffMatrixPanel.setLayout(new java.awt.GridLayout(2, 2));

      payoff00FormattedTextField.setColumns(5);
      payoff00FormattedTextField.setValue(new Float (1));
      payoff00FormattedTextField.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
         public void propertyChange(java.beans.PropertyChangeEvent evt) {
            payoffFormattedTextFieldPropertyChange(evt);
         }
      });
      payoffMatrixPanel.add(payoff00FormattedTextField);

      payoff01FormattedTextField.setColumns(5);
      payoff01FormattedTextField.setValue(new Float (0));
      payoff01FormattedTextField.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
         public void propertyChange(java.beans.PropertyChangeEvent evt) {
            payoffFormattedTextFieldPropertyChange(evt);
         }
      });
      payoffMatrixPanel.add(payoff01FormattedTextField);

      payoff10FormattedTextField.setColumns(5);
      payoff10FormattedTextField.setValue(new Float (1.5));
      payoff10FormattedTextField.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
         public void propertyChange(java.beans.PropertyChangeEvent evt) {
            payoffFormattedTextFieldPropertyChange(evt);
         }
      });
      payoffMatrixPanel.add(payoff10FormattedTextField);

      payoff11FormattedTextField.setColumns(5);
      payoff11FormattedTextField.setValue(new Float (0.5));
      payoff11FormattedTextField.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
         public void propertyChange(java.beans.PropertyChangeEvent evt) {
            payoffFormattedTextFieldPropertyChange(evt);
         }
      });
      payoffMatrixPanel.add(payoff11FormattedTextField);

      add(payoffMatrixPanel);
   }// </editor-fold>//GEN-END:initComponents

	 private void payoffFormattedTextFieldPropertyChange (java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_payoffFormattedTextFieldPropertyChange
		if (evt.getPropertyName ().equals ("value")) {
			this.updateInfoPanel (true);
		}
	 }//GEN-LAST:event_payoffFormattedTextFieldPropertyChange


   // Variables declaration - do not modify//GEN-BEGIN:variables
   private javax.swing.JFormattedTextField payoff00FormattedTextField;
   private javax.swing.JFormattedTextField payoff01FormattedTextField;
   private javax.swing.JFormattedTextField payoff10FormattedTextField;
   private javax.swing.JFormattedTextField payoff11FormattedTextField;
   private javax.swing.JPanel payoffMatrixPanel;
   // End of variables declaration//GEN-END:variables

}

// Local Variables:
// mode: java
// mode: flyspell-prog
// ispell-local-dictionary: "british"
// End:
